<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>登录／注册</title>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<meta charset="utf-8">
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">
<meta content="yes" name="apple-mobile-web-app-capable">
<meta content="black" name="apple-mobile-web-app-status-bar-style">
<meta content="telephone=no" name="format-detection">
<link rel="stylesheet" href="/styles/reset.css">
<link rel="stylesheet" href="/styles/login.css">
</head>
<body>
	<div class="main">
		<div class="nav clearfix"></div>
		<img class="logo" src="/images/logo.png" alt="">
		<div class="dInput clearfix">
			<img class="pull-left" src="/images/input1.png" alt="">
			<div class="input1 pull-left">
				<input type="text" placeholder="请输入您的手机号码" id="test" maxlength="13">
			</div>
		</div>
		<div class="dInput clearfix">
			<img class="pull-left" src="/images/input2.png" alt="">
			<div class="input2 pull-left">
				<input type="text" class="importCode" id="codeVal" placeholder="请输入验证码" maxlength="6">
				<input type="button" id="btn" value="获取验证码" onclick="sendemail()" class="pull-right code" />
			</div>
		</div>
		<div class="btn">
			<p>无需注册，输入手机号即可登录</p>
			<a href="javascript:;" onclick="login()" class="loginBtn">登录／注册</a>
		</div>

		<!-- 输入手机验证提示 -->
		<div class="popup-wrap">
			<div class="popup-prompt">
				<dt>
					<img src="/images/wrong.png">
				</dt>
				<dd>请输入正确的手机号码</dd>
			</div>
		</div>
	</div>
</body>
<script src="/scripts/jquery.min.js"></script>
<script src="/scripts/rem.js"></script>
<script type="text/javascript">
	//var countdown=60; 
	function login() {
		var ipone = $("#test").val();
		var code = $("#codeVal").val();
		var data = {
			ihone : ipone,
			code : code
		}
		//
		$.ajax({
			type : "POST", //提交方式 
			url : "/login",//路径 
			data : {
				ihone : ipone,
				code : code
			},//数据，这里使用的是Json格式进行传输 
			success : function(result) {//返回数据根据结果进行相应的处理 
				console.log(result)
				 if (result == "1") {
					 window.location.href = "/shop/wx"; 
				}else{
					$(".popup-wrap dd").html("验证码输入有误！");
					$('.popup-wrap').show().delay(3000).fadeOut();					
				} 
			}
		});
	}

	var countdown = 60;
	function sendemail() {
		var val = $("#test").val();
		var obj = $("#btn");
		$.ajax({
			type : "POST", //提交方式 
			url : "/getCaptcha",//路径 
			data : {
				val : val
			},//数据，这里使用的是Json格式进行传输 
			success : function(result) {//返回数据根据结果进行相应的处理 
				console.log(result)
			}
		});
		
		var tel = $("#test").val();
		var telLength = tel.length;
		var reg = /^1([38]\d|4[57]|5[0-35-9]|7[06-8])(\-\d{4}){2}$/;
		if (!reg.test(tel)) {
			$('.popup-wrap').show().delay(3000).fadeOut();
			
		} else if (telLength <= 12) {
			$('.popup-wrap').show().delay(3000).fadeOut();
		} else {
			var obj = $("#btn");
			settime(obj);
		}
	}
	function settime(obj) { //发送验证码倒计时
		if (countdown == 0) {
			obj.attr('disabled', false);
			// obj.removeattr("disabled"); 
			obj.val("获取验证码");
			countdown = 60;
			return;
		} else {
			obj.attr('disabled', true);
			obj.val("重新发送(" + countdown + ")");
			countdown--;
		}
		setTimeout(function() {
			settime(obj)
		}, 1000)
	}

	$('#test').eq(0).on('keyup', function(e) {
		var backSpaceCode = e.keyCode;
		var temp = '-';
		var str = '-';
		if (backSpaceCode != 8 && $(this).val().length == 4) {
			str = $(this).val().slice(3);
			temp = $(this).val().slice(0, 3);
			$(this).val(temp + '-' + str)
		} else if (backSpaceCode != 8 && $(this).val().length == 9) {
			str = $(this).val().slice(8);
			temp = $(this).val().slice(0, 8);
			$(this).val(temp + '-' + str)
		}
		
	})
	// 点击登录提示
	$(".loginBtn").on('click', function() {
		if ($("#test").val() == "") {
			// alert("手机号码为空");
			$(".popup-wrap dd").html("手机号码为空");
			$('.popup-wrap').show().delay(3000).fadeOut();
		} else if ($("#codeVal").val() == "") {
			// alert("验证码不得为空");
			$(".popup-wrap dd").html("验证码不得为空");
			$('.popup-wrap').show().delay(3000).fadeOut();
		}
	})
</script>
</html>
